package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.WebService;

import java.util.HashMap;
import java.util.Map;
/**
 * 赛特斯ISA系统平台查询频道
 * STS_WebService_Imp_QueryTheChannel
 * @author xuzhi
 *
 */
public class STS_WebService_Imp_QueryTheChannel implements WorkInterFace {

	@Override
	public String getName() {
		return "赛特斯ISA系统平台查询频道";
	}

	@Override
	public String getDesciption() {
		return "";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in=new Attr[2];
//		in[0]=new Attr("AlarmBeginTime", "需要查询的故障开始时间,YYYY-MM-DD-HH-MM例如：2012-12-14-20-15", AttrType.TYPE_String, true);
//		in[1]=new Attr("AlarmFinishTime","需要查询的故障结束时间,YYYY-MM-DD-HH-MM例如：2012-12-14-22-15",AttrType.TYPE_String,true);
		in[0]=new Attr("ChannelName","频道名称", AttrType.TYPE_String,true);
		in[1]=new Attr("AreaCode", "本地网：杭州:HZ宁波：NB 湖州:HU绍兴：SX嘉兴：JX金华：JH衢州:QZ丽水：LS舟山：ZS台州：TZ温州：WZ", AttrType.TYPE_String, true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[5];
		out[0]=new Attr("ReturnCode", "0表示成功，1表示交互失败2业务账号/宽带账号不存在3 频道名称不匹配4 超时5 其他", AttrType.TYPE_Int, true);	
		out[1]=new Attr("ChannelName", "需要10000号做关键字联想，赛特斯系统中的频道名称见附表", AttrType.TYPE_String, true);
		out[2]=new Attr("RealTimeResult", "只填”达标/不达标”赛特斯内部根据MOS来判断，MOS<3为不达标。", AttrType.TYPE_String, true);
		out[3]=new Attr("log", "服务器返回的soapxml", AttrType.TYPE_String, true);
		out[4]=new Attr("Errormsg", "服务器返回的错误信息,当ReturnCode为0的时候就不必去读取", AttrType.TYPE_String, false);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		AttrsIn attrsIn=new AttrsIn();
		WebService webService=new WebService();
		Map<String,Object> map=new HashMap<String, Object>();
		//Get into arguments
		attrsIn.setClientSysName("CDMA");
		attrsIn.setFunctionName("getReceptBill_pd");
		attrsIn.setRequestMessage("<NETACTION_NAME>ISA系统查询机顶盒</NETACTION_NAME>"+
					"<CALL_METHOD>receptBill</CALL_METHOD>"+
					"<ReceptFlag>1</ReceptFlag>"+
					"<SourceDept>IPTV_10000</SourceDept>"+
					"<AlarmBeginTime>"+webService.timeget(1)+"</AlarmBeginTime>"+
					"<AlarmFinishTime>"+webService.timeget(0)+"</AlarmFinishTime>"+
					"<ChannelName>"+(String) data.get("ChannelName")+"</ChannelName>"+
					"<AreaCode>"+(String) data.get("AreaCode")+"</AreaCode>"+
					"<Remark>IPTV服务质量保障系统</Remark>");
		//Get soapxml
		String returnXml=webService.WebServiceInit(attrsIn);
		String flag=webService.getPattern("flag", returnXml);
		if(flag.equals("true")){
			map.put("ReturnCode", webService.getPattern("ReturnCode", returnXml));
			map.put("ChannelName",  webService.getPattern("ChannelName",webService.getPattern("Report", returnXml)));
			map.put("RealTimeResult",  webService.getPattern("RealTimeResult",webService.getPattern("Report", returnXml)));
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "");
			map.put("flag",1);
		}else{
			map.put("flag",0);
			map.put("ReturnCode", webService.getPattern("ReturnCode", returnXml));
			map.put("ChannelName", "" );
			map.put("RealTimeResult","");
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "网元侧执行出错，处理请求失败");
		}
		
		return map;
	}

}
